package org.platform.service.system;

import com.mc.mic.core.log.bus.BusLog;
import com.mc.mic.core.log.bus.BusLogMapper;
import org.apache.commons.lang3.StringUtils;
import org.platform.mo.csmo.cmd50001.QueryLogInfoRequestParam;
import org.platform.mo.csmo.cmd50001.QueryLogInfoResponseParam;
import org.platform.mo.csmo.common.FD_BusLog;
import org.platform.service.IBaseService;
import org.platform.tool.util.BeansUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author FengJie
 * @date 2018/8/21
 */
@Service
public class LogInfoServiceImpl implements IBaseService {
    @Autowired
    private BusLogMapper mapper;

    public QueryLogInfoResponseParam queryLogInfo(QueryLogInfoRequestParam requestParam) {
        QueryLogInfoResponseParam responseParam = new QueryLogInfoResponseParam();

        Example example = new Example(BusLog.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(requestParam.getDiagnoseId())) {
            criteria.andLike("taskId", "%" + requestParam.getDiagnoseId() + "%");
        }
        if (StringUtils.isNotEmpty(requestParam.getStartTime())) {
            criteria.andGreaterThanOrEqualTo("timeTag", requestParam.getStartTime());
        }
        if (StringUtils.isNotEmpty(requestParam.getEndTime())) {
            criteria.andLessThanOrEqualTo("timeTag", requestParam.getEndTime());
        }
        example.orderBy("timeTag").desc();
        List<BusLog> busLogList = mapper.selectByExample(example);
        List<FD_BusLog> logInfoList = BeansUtils.copyListProperties(busLogList, FD_BusLog.class);
        responseParam.setLogList(logInfoList);
        return responseParam;
    }
}
